package com.heima.controller;

import com.heima.common.Result;
import com.heima.pojo.region.Region;
import com.heima.pojo.region.RegionPageResult;
import com.heima.pojo.region.RegionQueryParam;
import com.heima.pojo.region.RegionVO;
import com.heima.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "区域管理相关接口")
@RequestMapping("/api/vm-service")
@RequiredArgsConstructor
public class RegionController {
    private final RegionService regionService;

    /**
     * 区域搜索
     * @param param
     * @return
     */
    @GetMapping("/region/search")
    @ApiOperation("区域搜索")
    public RegionPageResult search(RegionQueryParam param){
        log.info("区域搜索参数:{}",param);
        return regionService.search(param);
    }
    /**
     * 新增区域
     */
    @PostMapping("/region")
    @ApiOperation("新增区域")
    public void addRegion(@RequestBody Region region){
        log.info("新增区域:{}",region);
        regionService.addRegion(region);
    }

    /**
     * 修改区域
     */
    @PutMapping("/region/{regionId}")
    @ApiOperation("修改区域")
    public void updateRegion(@PathVariable String regionId,@RequestBody Region region){
        log.info("修改区域:{}" ,region);
        region.setRegionId(regionId);
        regionService.updateRegion(region);
    }
    /**
     * 根据id查询区域
     */
    @GetMapping("/region/{regionId}")
    @ApiOperation("根据id查询区域")
    public RegionVO getById(@PathVariable String regionId){
        log.info("根据id查询区域:{}",regionId);
        return regionService.getById(regionId);
    }

    /**
     * 删除区域
     */
    @ApiOperation("删除区域")
    @DeleteMapping("/region/{regionId}")
    public void deleteRegion(@PathVariable String regionId){
        log.info("删除区域:{}",regionId);
        regionService.deleteRegion(regionId);
    }
}
